//这个文件是用来统一发送请求的，以便于将来统一维护或是管理，比如更改接口
// 1.引入ajax
import ajax from "./ajax";
import mockAjax from "./mockAjax";
// 2.发送请求，获取三级分类列表的数据
// export function reqGetBaseCategoryList() {
//   return ajax.get("/product/getBaseCategoryList");
// }
//可以简写成下面的形式
export const reqGetBaseCategoryList = () =>
  ajax.get("/product/getBaseCategoryList");

// 发送请求，获取轮播图的数据
export const reqGetBannerListData = () => mockAjax.get("/banner");

// 发送请求，获取楼层的数据
export const reqGetFloorsListData = () => mockAjax.get("/floors");

// 发送请求，获取搜索商品的数据
// export const reqGetGoodsInfoData = (searchParams) => {
//   // return ajax.post("/list", searchParams);
//   return ajax({
//     url: "/list",
//     method: "post",
//     data: searchParams,
//   });
// };
export const reqGetGoodsInfoData = (searchParams) =>
  ajax.post("/list", searchParams);

// 获取商品详情数据
export const reqGetGoodDetailInfoData = (id) => ajax.get(`/item/${id}`);

//添加选择的商品到服务器端
export const reqAddOrUpdateCart = (skuId, skuNum) =>
  ajax.post(`/cart/addToCart/${skuId}/${skuNum}`);

// 获取购物车中的数据
export const reqGetShopCartListData = () => ajax.get("/cart/cartList");

// 切换购物车中商品的选中状态
export const reqChangeCartState = (skuID, isChecked) =>
  ajax.get(`/cart/checkCart/${skuID}/${isChecked}`);

// 批量更新购物车中商品全选的功能
// export const reqChangeAllCartState = (isChecked, skuIdList) => {
//   return ajax.post(`/api/cart/batchCheckCart/${isChecked}`,skuIdList)
// }

// export const reqChangeAllCartState = (isChecked, skuIdList) => ajax.post(`/cart/batchCheckCart/${isChecked}`,skuIdList)

// export const reqChangeAllCartState = (isChecked, skuIdList) => {
//   return ajax({
//     url: `/cart/batchCheckCart/${isChecked}`,
//     method: 'post',
//     data:skuIdList
//   })
// }

// 当大括号中只有一行代码的时候，可以省略return和大括号
export const reqChangeAllCartState = (isChecked, skuIdList) =>
  ajax({
    url: `/cart/batchCheckCart/${isChecked}`,
    method: "post",
    data: skuIdList,
  });

//删除购物车中一条商品数据
export const reqDelOneShopCartInfo = (skuId) =>
  ajax.delete(`/cart/deleteCart/${skuId}`);

// export const reqDelOneShopCartInfo = skuId => {
//   return ajax({
//     url: `/cart/deleteCart/${skuId}`,
//     method: 'delete'
//   })
// }

//批量删除购物车中的商品数据
export const reqDelSelectedShopCartInfo = (skuIdList) =>
  ajax.delete(`/cart/batchDeleteCart`, { data: skuIdList });

//获取验证码
export const reqGetVerifyCode = (phone) =>
  ajax.get(`/user/passport/sendCode/${phone}`);

//实现注册
export const reqUserRegister = (user) =>
  ajax.post("/user/passport/register", user);

//实现登陆的接口
export const reqUserLogin = (user) => ajax.post("/user/passport/login", user);

//实现登出
export const reqUserLogout = () => ajax.get("/user/passport/logout");

//获取订单配送地址,好像暂时没有

//获取订单交易信息
export const reqGetTradeInfoData = () => ajax.get("/order/auth/trade");

//将订单信息提交给服务器
export const reqSubmitOrder = (tradeNo, params) =>
  ajax.post(`/order/auth/submitOrder?tradeNo=${tradeNo}`, params);

//获取订单支付信息 也就是会根据付款接口响应回来的地址生成的二维码
export const reqGetPaymentInfo = (orderId) =>
  ajax.get(`/payment/weixin/createNative/${orderId}`);

// 查询订单支付状态;
export const reqGetPayOrderState = (orderId) =>
  ajax.get(`/payment/weixin/queryPayStatus/${orderId}`);

// 21. 查询订单中心数据
export const reqGetOrderList = (page, limit) =>
  ajax.get(`/order/auth/${page}/${limit}`);
